package com.compass.mobile.ui.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.leanback.widget.ArrayObjectAdapter
import androidx.leanback.widget.BaseGridView
import androidx.leanback.widget.FocusHighlight
import androidx.leanback.widget.FocusHighlightHelper
import com.compass.mobile.callback.OnItemClickListener
import com.compass.mobile.databinding.FragmentBookingRegisterBinding
import com.compass.mobile.framework.base.BaseVBFragment
import com.compass.mobile.framework.ext.onClick
import com.compass.mobile.framework.utils.FocusViewUtils
import com.compass.mobile.framework.utils.dpToPx
import com.compass.mobile.models.Title
import com.compass.mobile.presenters.DatePresenter
import com.compass.mobile.presenters.DoctorPresenter
import com.compass.mobile.ui.activity.DoctorRegisterHomeActivity
import com.compass.mobile.widget.MyBridgeAdapter

/**
 * Description： 预约挂号fragment
 * Date:2024/5/23 15:48
 */
class BookingRegistrationFragment : BaseVBFragment<FragmentBookingRegisterBinding>() {



    override fun initView(view: View, savedInstanceState: Bundle?) {
        specialColumn()
        initDate()
        FocusViewUtils.scaleView(mBinding?.tvPrevious, 1)
        FocusViewUtils.scaleView(mBinding?.tvNextPage, 1)
    }

    override fun intListener() {
        mBinding?.tvPrevious?.onClick {
            showToast("上一页")
        }

        mBinding?.tvNextPage?.onClick {
            showToast("下一页")
        }
    }


    private val onItemClickListener: OnItemClickListener = object : OnItemClickListener {
        override fun onItemClick(position: Int, view: View) {
            showToast("点击了item==$position")



        }
    }

    @SuppressLint("RestrictedApi")
    fun specialColumn() {
        mBinding?.caseItem?.setNumColumns(2)
        mBinding?.caseItem?.horizontalSpacing = dpToPx(10)
        val departmentIntroductionPresenter = DoctorPresenter("1")
        val arrayObjectAdapter = ArrayObjectAdapter(departmentIntroductionPresenter)
        val itemBridgeAdapter = MyBridgeAdapter(
            requireContext(),
            arrayObjectAdapter, onItemClickListener
        )
        mBinding?.caseItem?.setAdapter(itemBridgeAdapter)
        mBinding?.caseItem?.setFocusScrollStrategy(BaseGridView.FOCUS_SCROLL_ITEM)
        arrayObjectAdapter.addAll(0, specialColumns)
        FocusHighlightHelper.setupBrowseItemFocusHighlight(
            itemBridgeAdapter,
            FocusHighlight.ZOOM_FACTOR_SMALL, false
        )

    }


    @SuppressLint("RestrictedApi")
    private fun initDate() {
        mBinding?.gridDate?.horizontalSpacing = dpToPx(10)
        val arrayObjectAdapter = ArrayObjectAdapter(DatePresenter())
        val itemBridgeAdapter = MyBridgeAdapter(
            requireContext(),
            arrayObjectAdapter, onItemClickListener
        )
        mBinding?.gridDate?.setAdapter(itemBridgeAdapter)
        mBinding?.gridDate?.setFocusScrollStrategy(BaseGridView.FOCUS_SCROLL_ITEM)
        arrayObjectAdapter.addAll(0, dates)
        FocusHighlightHelper.setupBrowseItemFocusHighlight(
            itemBridgeAdapter,
            FocusHighlight.ZOOM_FACTOR_SMALL, false
        )
        mBinding?.gridDate?.selectedPosition = 3
    }


    companion object {


        val specialColumns: List<Title?>
            get() {
                val titleList: MutableList<Title?> = ArrayList()
                titleList.add(Title("刘建国", "￥48元/次"))
                titleList.add(Title("张建国", "￥48元/次"))
                return titleList
            }

        val dates: List<Title?>
            get() {
                val titleList: MutableList<Title?> = ArrayList()
                titleList.add(Title("星期一", "5.1"))
                titleList.add(Title("星期二", "5.2"))
                titleList.add(Title("星期三", "5.3"))
                titleList.add(Title("星期四", "5.4"))
                titleList.add(Title("星期武", "5.5"))
                titleList.add(Title("星期六", "5.6"))
                titleList.add(Title("星期日", "5.7"))
                titleList.add(Title("星期一", "5.8"))
                titleList.add(Title("星期二", "5.9"))
                titleList.add(Title("星期三", "5.10"))
                titleList.add(Title("星期四", "5.11"))
                titleList.add(Title("星期武", "5.12"))
                titleList.add(Title("星期六", "5.13"))
                titleList.add(Title("星期日", "5.14"))
                titleList.add(Title("星期一", "5.15"))
                titleList.add(Title("星期二", "5.16"))
                titleList.add(Title("星期三", "5.17"))
                titleList.add(Title("星期四", "5.18"))
                titleList.add(Title("星期武", "5.19"))
                titleList.add(Title("星期六", "5.20"))
                titleList.add(Title("星期日", "5.21"))
                return titleList
            }
    }
}